home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / nslookup / commands.l < prev    next >
Encoding:
Lex Description  |  1988-11-27  |  4.6 KB  |  170 lines

  1. %{
  2.  
  3. /*
  4.  * Copyright (c) 1985 Regents of the University of California.
  5.  * All rights reserved.
  6.  *
  7.  * Redistribution and use in source and binary forms are permitted
  8.  * provided that the above copyright notice and this paragraph are
  9.  * duplicated in all such forms and that any documentation,
  10.  * advertising materials, and other materials related to such
  11.  * distribution and use acknowledge that the software was developed
  12.  * by the University of California, Berkeley.  The name of the
  13.  * University may not be used to endorse or promote products derived
  14.  * from this software without specific prior written permission.
  15.  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
  16.  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  17.  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  18.  *
  19.  *    @(#)commands.l    5.9 (Berkeley) 6/18/88
  20.  */
  21.  
  22. /*
  23.  *******************************************************************************
  24.  *
  25.  *  commands.l
  26.  *
  27.  *      Andrew Cherenson     CS298-26  Fall 1985
  28.  *
  29.  *    Lex input file for the nslookup program command interpreter.
  30.  *    When a sequence is recognized, the associated action
  31.  *    routine is called. The action routine may need to
  32.  *    parse the string for additional information.
  33.  *
  34.  *  Recognized commands: (identifiers are shown in uppercase)
  35.  *
  36.  *    server NAME    - set default server to NAME, using default server
  37.  *    lserver NAME    - set default server to NAME, using initial server
  38.  *    finger [NAME]    - finger the optional NAME
  39.  *    exit        - exit the program
  40.  *    root        - set default server to the root
  41.  *    ls NAME        - list the domain NAME
  42.  *    view FILE    - sorts and view the file with more
  43.  *    set OPTION    - set an option
  44.  *    help         - print help information
  45.  *    ?         - print help information
  46.  *    opt[ions]    - print options, current server, host
  47.  *    NAME        - print info about the host/domain NAME 
  48.  *              using default server.
  49.  *    NAME1 NAME2    - as above, but use NAME2 as server
  50.  *
  51.  *
  52.  *   yylex Results:
  53.  *    0        upon end-of-file.
  54.  *    1        after each command.
  55.  *  
  56.  *******************************************************************************
  57.  */
  58.  
  59. #include "res.h"
  60. extern char rootServerName[];
  61.  
  62. %}
  63. WS    [ \t]
  64. LET    [A-Za-z0-9.*]
  65. NAME    [A-Za-z0-9.*=_/-]
  66. %%
  67. ^{WS}*server{WS}+{LET}{NAME}*{WS}*$     { 
  68.                         /* 
  69.                          * 0 == use current server to find
  70.                          *        the new one.
  71.                          * 1 == use original server to find
  72.                          *        the new one.
  73.                          */
  74.                         SetDefaultServer(yytext, 0); 
  75.                         return(1);
  76.                     }
  77. ^{WS}*lserver{WS}+{LET}{NAME}*{WS}*$     { 
  78.                         SetDefaultServer(yytext, 1); 
  79.                         return(1);
  80.                     }
  81. ^{WS}*exit{WS}*$             { 
  82.                         return(0);
  83.                     }
  84. ^{WS}*root{WS}*$             { 
  85.                         SetDefaultServer(rootServerName, 1);
  86.                         return(1);
  87.                     }
  88. ^{WS}*finger({WS}+{LET}{NAME}*)?{WS}+>>?{WS}*{NAME}+{WS}*$     {
  89.                         /* 
  90.                          * 2nd arg. 
  91.                          *  0 == output to stdout
  92.                          *  1 == output to file
  93.                          */
  94.                         Finger(yytext, 1); 
  95.                         return(1);
  96.                     }
  97. ^{WS}*finger({WS}+{LET}{NAME}*)?{WS}*$     { 
  98.                         Finger(yytext, 0); 
  99.                         return(1);
  100.                     }
  101. ^{WS}*view{WS}+{NAME}+{WS}*$     { 
  102.                         ViewList(yytext); 
  103.                         return(1);
  104.                     }
  105. ^{WS}*ls{WS}+(("-a"|"-h"|"-m"|"-s"|"-d"){WS}+)?{LET}{NAME}*{WS}+>>?{WS}+{NAME}+{WS}*$    { 
  106.                           /* 
  107.                            * 2nd arg. 
  108.                            *  0 == output to stdout
  109.                          *  1 == output to file
  110.                          */
  111.                         ListHosts(yytext, 1);
  112.                         return(1);
  113.                     }
  114. ^{WS}*ls{WS}+(("-a"|"-h"|"-m"|"-s"|"-d"){WS}+)?{LET}{NAME}*{WS}*$     { 
  115.                         ListHosts(yytext, 0);
  116.                         return(1);
  117.                     }
  118. ^{WS}*set{WS}+{NAME}+{WS}*$         { 
  119.                         SetOption(yytext); 
  120.                         return(1);
  121.                     }
  122. ^{WS}*help{WS}*$             { 
  123.                         extern void PrintHelp();
  124.  
  125.                         PrintHelp();
  126.                         return(1);
  127.                     }
  128. ^{WS}*"?"{WS}*$             { 
  129.                         PrintHelp();
  130.                         return(1);
  131.                     }
  132. ^{WS}*opt(ions)?{WS}*$             { 
  133.                         ShowOptions(TRUE); 
  134.                         return(1);
  135.                     }
  136. ^{WS}*{LET}{NAME}*{WS}+>>?{WS}*{NAME}+{WS}*$     {
  137.                         /* 
  138.                          * 0 == output to stdout
  139.                          * 1 == output to file
  140.                          */
  141.                         LookupHost(yytext, 1); 
  142.                         return(1);
  143.                     }
  144. ^{WS}*{LET}{NAME}*{WS}*$        {
  145.                         LookupHost(yytext, 0); 
  146.                         return(1);
  147.                     }
  148. ^{WS}*{LET}{NAME}*{WS}+{LET}{NAME}*{WS}+>>?{WS}*{NAME}+{WS}*$     {
  149.                         /* 
  150.                          * 0 == output to stdout
  151.                          * 1 == output to file
  152.                          */
  153.                         LookupHostWithServer(yytext, 1); 
  154.                         return(1);
  155.                     }
  156. ^{WS}*{LET}{NAME}*{WS}+{LET}{NAME}*{WS}*$    {
  157.                         LookupHostWithServer(yytext, 0); 
  158.                         return(1);
  159.                     }
  160. ^{WS}*\n                { 
  161.                         return(1);
  162.                     }
  163. ^.*\n                    { 
  164.                         printf("Unrecognized command: %s", 
  165.                                 yytext); 
  166.                         return(1);
  167.                     }
  168. \n                    { ; }
  169. %%
  170.